<?php
namespace app\index\controller;
use think\Session;

use Think\Controller;
use think\Request;
use app\index\model\User;

class Risk  extends \think\Controller {
	
	
	public function risk_list() {
		return $this -> fetch();
	}

	//航运新闻数据
	public function risk_news() {
	
		$list = User::all();
		//获取数据总条数
		$count = count($list);
		//获取每页显示的条数
		$limit = Request::instance()->param('limit');
		//获取当前页数
		 $page= Request::instance()->param('page');
		 $goods = \think\Db::table('gat_news') -> limit( ($page-1)*$limit,$limit )->select();
		return ["code"=>"0","msg"=>"","data"=>$goods,"count"=>$count];
		
	}
	
	//航运新闻数据修改
	public function risk_modify() {
		$this->local_hash =  $_SERVER['QUERY_STRING'];
		$hash = $this->local_hash;
		Session::set('id', $hash);
		
		$risk_list = User::where('id', $hash)->find();
		
		$news_tit = $risk_list ['title'];
		$news = $risk_list ['news'];
		$this->assign('news_tit',$news_tit);
        $this->assign('news',$news);
		
		return $this -> fetch();
		
	}
	
	//更新新闻数据
	public function  risk_update() {
		
		$session_name = Session::get('id');
		 
		if (Request::instance()->isPost()){
			
			$data = ['title' => $_POST['news_title'], 'news' => $_POST['news_content']];
				
			User::where('id', $session_name)->update($data);	
			
			
		} 
	}
	
	//新增航运新闻数据
	public function risk_add() {
		return $this -> fetch();
	}
	
	//插入新增新闻数据
	public function risk_insert() {
			if (Request::instance()->isPost()){
					$data = ['title' => $_POST['news_title'], 'news' => $_POST['news_content']];
				$user = new User;
				$user->save($data);
				
		} 
	}
	
	//新闻数据删除
	public function risk_del(Request $request) {
		$request = Request::instance();
		if($request -> method() == 'POST'){
			$id = $_POST['id'];
			User::where('id',$id)->delete();
		}else{
			return '请使用post提交';
		}
	}
	
//	//新闻模糊搜索
//	public function fuzzy_query() {
//		if (Request::instance()->isPost()){
//			//$key  = $_POST['name'];
//			\think\Db::table('gat_news')->where('title',['like','%1%'])->find();
////					$data = ['title' => $_POST['news_title'], 'news' => $_POST['news_content']];
////				\think\Db::name('gat_news')->insert($data);	
//		} 
//	}
}
?>